#include <iostream>
#include "framework/service_bus_v2.h"
#include "database/redis_pool.h"

using namespace cpp_backend::framework;

int main() {
    // 初始化Redis连接池
    auto& redis_pool = cpp_backend::database::RedisPool::Instance();
    if (!redis_pool.Initialize()) {
        std::cerr << "Failed to initialize Redis pool" << std::endl;
        return 1;
    }

    // 初始化ServiceBusV2
    auto& bus = ServiceBusV2::Instance();
    bus.Initialize(&redis_pool);

    // 构造请求
    Request req;
    req.SetMethod("GET");
    req.SetPath("/api/ping");
    req.SetRequestId("sb2-test-001");

    // 调用 ping_service（需先启动对应微服务进程）
    auto resp = bus.CallService("ping_service", req);

    std::cout << "HTTP: " << resp.GetHttpStatusCode()
              << ", code: " << resp.GetErrorCodeValue()
              << ", msg: " << resp.GetMessage() << std::endl;
    if (!resp.GetData().is_null()) {
        std::cout << resp.GetData().dump() << std::endl;
    }

    return resp.IsSuccess() ? 0 : 2;
}

